package com.zidongxiangxi.lock.redis;

import com.zidongxiangxi.lock.core.DistributedLock;
import com.zidongxiangxi.lock.core.DistributedLockFactory;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;

/**
 * This is Description
 *
 * @author chenxudong
 * @date 2021/12/30
 */
public class RedisDistributedLockFactory implements DistributedLockFactory {
    private final String application;
    private final RedissonClient redissonClient;

    public RedisDistributedLockFactory(String application, RedissonClient redissonClient) {
        this.application = application;
        this.redissonClient = redissonClient;
    }

    @Override
    public DistributedLock createLock(String lockName) {
        RLock rLock = redissonClient.getLock(application + ":" + lockName);
        return new RedisDistributedLock(rLock);
    }
}
